<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="所属门店" class="myform-item">
          <el-select v-model="form.shop_id" placeholder="请选择">
            <el-option
              v-for="item in shopList"
              :key="item.id"
              :label="item.shop_name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择日期">
          <el-date-picker
            v-model="form.strtime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary">查询</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%">
      <template v-for="(item, index) in tableHeader">
        <el-table-column
          v-if="!item.date"
          :label="item.week"
          :key="index"
          align="center"
          :prop="item.key"
        ></el-table-column>
        <el-table-column v-else :label="item.date" :key="item.date" align="center">
          <el-table-column :label="item.week" align="center" :prop="item.key"></el-table-column>
        </el-table-column>
      </template>
    </el-table>
    <pagination />
  </div>
</template>

<script>
import { getApiGetshoplist, postApiApischeduling } from "@/api";
import { getCurrentTime } from "@/utils/time.js";
import pagination from '@/components/pagination.vue';
export default {
  name: "Home",
  components: { pagination },
  data() {
    return {
      loading: true,
      form: {
        shop_id: "",
        strtime: "",
      },
      shopList: [],
      tableHeader: [],
      tableData: [],
    };
  },
  async activated() {
    this.form.strtime = getCurrentTime();
    await this.getApiGetshoplist();
    await this.postApiApischeduling();
    this.loading = false
  },
  methods: {
    //门店列表
    async getApiGetshoplist() {
      await getApiGetshoplist().then((res) => {
        console.log("门店列表", res);
        this.form.shop_id = res.data[0].id;
        this.shopList = res.data;
      });
    },
    // 排班表
    async postApiApischeduling() {
      let form = JSON.parse(JSON.stringify(this.form));
      form.shop_id = Number(form.shop_id);
      let data = form;
      await postApiApischeduling(data).then((res) => {
        console.log("排班表", res);
        this.tableHeader = res.data.list;
        this.tableData = res.data.data;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  border-radius: 2px;
  @include global-back;
  @include boxShadow;
}
</style>
